import java.util.Arrays;

public class Solution646 {
    public int findLongestChain(int[][] pairs) {
        Arrays.sort(pairs,(a,b)->a[1]==b[1]?a[0]-b[0]:a[1]-b[1]);
        int ans=1,cur=pairs[0][1];
        for (int i=1;i<pairs.length;i++){
            if (pairs[i][0]>cur){
                ans++;
                cur=pairs[i][1];
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution646().findLongestChain(new int[][]{{1,2},{2,3},{3,4}}));
    }
}
